#!/usr/bin/env bash

export MISE_LOCKFILE=1
export MISE_EXPERIMENTAL=1

touch mise.lock
assert "mise install tiny@1.0.0"
assert "mise use tiny@1"
assert "mise install tiny@1.0.1"
assert "mise config get -f mise.toml tools.tiny" "1"
assert "mise where tiny" "$MISE_DATA_DIR/installs/tiny/1.0.0"
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0"
assert "cat mise.lock" '[[tools.tiny]]
version = "1.0.0"
backend = "asdf:tiny"'

assert "mise use tiny@1"
assert "cat mise.lock" '[[tools.tiny]]
version = "1.0.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0"

assert "mise up tiny"
assert "cat mise.lock" '[[tools.tiny]]
version = "1.1.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.1.0"

assert "mise up tiny --bump"
assert "cat mise.lock" '[[tools.tiny]]
version = "3.1.0"
backend = "asdf:tiny"'
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "3"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "3.1.0"

echo 'tools.tiny = "1.0.0"' >mise.lock
assert "mise use tiny@1 tiny@2"
assert "cat mise.lock" '[[tools.tiny]]
version = "1.0.0"
backend = "asdf:tiny"

[[tools.tiny]]
version = "2.1.0"
backend = "asdf:tiny"'
assert "mise uninstall --all tiny"
assert "mise install tiny"
assert "mise ls tiny --json --current | jq -r '.[0].requested_version'" "1"
assert "mise ls tiny --json --current | jq -r '.[0].version'" "1.0.0"
assert "mise ls tiny --json --current | jq -r '.[1].requested_version'" "2"
assert "mise ls tiny --json --current | jq -r '.[1].version'" "2.1.0"
